﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CommonLib;
using Project1.Model;
using Project1.View;
using System.Windows;
using System.Collections.ObjectModel;
using GalaSoft.MvvmLight.Messaging;
using GalaSoft.MvvmLight;

namespace Project1.ViewModel
{
    public class ModelRegisterFactoryVM:ViewModelBase
    {
        private CoreViewModel coreVM;
        private UserControlHalConWindow halconWindow;
        private UserControlRegistModel registModel;
        public ModelRegisterFactoryVM()
        {
            Messenger.Default.Register<int>(this, "WindowClose", OnWindownClose);
            InitModel();
        }


        public void InitModel()
        {
            coreVM = new  CoreViewModel();//test
            InitMain();
        }
        private readonly int COMP_WINDOW = 0;
        private readonly int COMP_REGISTER_CARD = 1;
        public void InitMain()
        {
            
            halconWindow = new UserControlHalConWindow() { DataContext = coreVM};
            halconWindow.LoadModelBtn.Visibility = Visibility.Hidden;
            halconWindow.SavePlanBtn.Visibility = Visibility.Hidden;
            halconWindow.MatchingBtn.Visibility = Visibility.Hidden;
            halconWindow.ifRegisterMode = true;
            registModel = new UserControlRegistModel() { DataContext = coreVM};

            AllViewList = new ObservableCollection<ItemModel>
            {
                new ItemModel(){NameStr = "窗口",ViewContent = halconWindow},
                new ItemModel(){NameStr = "注册参数卡",ViewContent = registModel},
            };
            V1 = AllViewList[COMP_WINDOW];
            V2 = AllViewList[COMP_REGISTER_CARD];
            V1.ViewContent = halconWindow;
            V2.ViewContent = registModel;
        }

        private void OnWindownClose(int msg)
        {
            coreVM.OnWindowClose();
        }

        private ObservableCollection<ItemModel> _allViewList;
        /// <summary>
        /// 界面集合
        /// </summary>
        public ObservableCollection<ItemModel> AllViewList
        {
            get { return _allViewList; }
            set { _allViewList = value; RaisePropertyChanged(() => AllViewList); }
        }

        private ItemModel _V1;
        /// <summary>
        /// 选择的项
        /// </summary>
        public ItemModel V1
        {
            get { return _V1; }
            set { _V1 = value; RaisePropertyChanged(() => V1); }
        }

        private ItemModel _V2;
        /// <summary>
        /// 选择的项
        /// </summary>
        public ItemModel V2
        {
            get { return _V2; }
            set { _V2 = value; RaisePropertyChanged(() => V2); }
        }
    }
}
